﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
    <script>
        layui.use(['jquery', 'form', 'table', 'common', 'treeTable', 'optimizeSelectOption', 'layer'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                layer = layui.layer,
                treeTable = layui.treeTable,
                common = layui.common;
            //加载数据
            wcLoading.close();
            var value = $.request("value");
            var parentform = $.request("parentform");
            var currentWindow = !parent[parentform] ? common.currentWindow() : parent[parentform];
            var name = $.request("name");
            var ids = $.request("ids");
            var rendertree = common.rendertreetable({
                elem: '#currentTableId',
                url: '/SystemOrganize/Organize/GetTreeGridJson',
                height: 'full-0',
                toolbar: false,//工具栏
                id: 'currentTableId',
                tree: {
                    iconIndex: 1,           // 折叠图标显示在第几列
                    isPidData: true,        // 是否是id、pid形式数据
                    idName: 'F_Id',  // id字段名称
                    pidName: 'F_ParentId',     // pid字段名称
                    arrowType: 'arrow2',
                    getIcon: 'ew-tree-icon-style2'
                },
                cols: [[
                    { type: 'checkbox' },
                    { field: 'F_FullName', title: '名称', width: 250 },
                    { field: 'F_EnCode', title: '编号', width: 200 },
                    {
                        field: 'F_CategoryId', title: '分类', width: 120,
                        templet: function (d) {
                            return top.clients.dataItems["OrganizeCategory"][d.F_CategoryId] == null ? "" : top.clients.dataItems["OrganizeCategory"][d.F_CategoryId];
                        }
                    },
                    {
                        field: 'F_EnabledMark', title: '有效', width: 60,
                        templet: function (d) {
                            if (d.F_EnabledMark == true) {
                                return "<input type='checkbox' checked='' lay-skin='primary' name='true' valuer='true'>";
                            } else {
                                return "<input type='checkbox' name='false'  lay-skin='primary' valuer='false'>";
                            }
                        }
                    }
                ]],
                done: function () {
                    rendertree.expandAll();
                    if (!!ids) {
                        rendertree.setChecked(ids.split(','));
                    }
                }
            });
            // 监听行双击事件
            treeTable.on('rowDouble(currentTableId)', function (obj) {
                var pvalue = obj.data.F_Id;
                var pname = obj.data.F_FullName;
                var pcode = obj.data.F_EnCode;
                common.modalConfirm("注：您确定要选择{编号：" + pcode + "，名称：" + pname + "}的数据吗？", function (r) {
                    if (r) {
                        if (!!pvalue) {
                            currentWindow.$('#' + value).val(pvalue);
                        }
                        if (!!pname) {
                            currentWindow.$('#' + name).val(pname);
                        }
                        common.modalClose();
                    }
                });
                return false;
            });
            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                queryJson = data.field.txt_keyword;
                common.reloadtreetable(rendertree, {
                    where: { keyword: queryJson },
                });
                return false;
            });
            // 监听清除操作
            form.on('submit(data-clear-btn)', function (data) {
                rendertree.removeAllChecked();
                return false;
            });
            // 监听提交操作
            form.on('submit(saveBtn)', function (data) {
                var checkStatus = rendertree.checkStatus(false);;
                var pvalue = [];
                var pname = [];
                var pcode = [];
                for (var i = 0; i < checkStatus.length; i++) {
                    pvalue.push(checkStatus[i].F_Id);
                    pname.push(checkStatus[i].F_FullName);
                    pcode.push(checkStatus[i].F_EnCode);
                }
                if (pvalue.length == 0) {
                    common.modalConfirm("注：您确定要清除选择的数据吗？", function (r) {
                        if (r) {
                            if (!!pvalue) {
                                currentWindow.$('#' + value).val(null);
                            }
                            if (!!pname) {
                                currentWindow.$('#' + name).val(null);
                            }
                            common.modalClose();
                        }
                    });
                }
                else {
                    common.modalConfirm("注：您确定要选择{编号：" + pcode.join(",") + ",名称：" + pname.join(",") + "}的数据吗？", function (r) {
                        if (r) {
                            if (!!pvalue) {
                                currentWindow.$('#' + value).val(pvalue.join(","));
                            }
                            if (!!pname) {
                                currentWindow.$('#' + name).val(pname.join(","));
                            }
                            common.modalClose();
                        }
                    });
                }
                return false;
            });
        });
    </script>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            @*<legend>搜索信息</legend>*@
            <div>
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">关键字:</label>
                            <div class="layui-input-inline">
                                <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input" placeholder="">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                            <button type="submit" class="layui-btn layui-btn-danger" lay-submit lay-filter="data-clear-btn"><i class="layui-icon">&#xe640;</i> 清 除</button>
                        </div>
                    </div>
                    <div class="layui-form-item layui-hide">
                        <button class="layui-btn" lay-submit id="submit" lay-filter="saveBtn">确认保存</button>
                    </div>
                </form>
            </div>
        </fieldset>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>